<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="岗位序列" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="positionCategory">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.positionCategory"
                dictCode="position_category"
                placeholder="请选择岗位序列"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="岗位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="postId">
              <j-search-select
                :disabled="formDisabled"
                v-model="model.postId"
                :dict="postIdDict"
                placeholder="请选择岗位"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="工作地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workAddress">
              <!-- <j-select-depart
                  :disabled="formDisabled"
                  v-model="model.workAddress"
                  placeholder="请选择工作地点"
                /> -->
              <a-input :disabled="formDisabled" v-model="model.workAddress" placeholder="请输入工作地点"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所需人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="requireQuantity">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                v-model="model.requireQuantity"
                placeholder="请输入所需人数"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学历要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="educationalRequirements">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.educationalRequirements" dictCode="educational_requirements" placeholder="请选择学历要求" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="性别要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sexRequirements">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.sexRequirements" dictCode="sex_requirements" placeholder="请选择性别要求" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="专业要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="professionalRequirement">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.professionalRequirement" dictCode="professional_requirement" placeholder="请选择专业要求" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="工作经验" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workExperience">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.workExperience" dictCode="work_experience" placeholder="请选择工作经验" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="薪资区间（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salarySection">
              <a-input :disabled="formDisabled" v-model="model.salarySection" placeholder="请输入薪资区间（元）" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="期待到岗时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expectationTime">
              <j-date :disabled="formDisabled" placeholder="请选择期待到岗时间" v-model="model.expectationTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JSearchSelect from '@/views/scy/components/JSearchSelect.vue'

  export default {
    name: 'ErpHrPostRequirementItemForm',
    components: {
      JSearchSelect
    },
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {},
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        postIdDict: 'sys_position,name,id,del_flag = 0 and audit_status=2',
        confirmLoading: false,
        validatorRules: {
          positionCategory: [
            { required: true, message: '请选择岗位序列!' }
          ],
          postId: [
            { required: true, message: '请选择岗位名称!' }
          ],
          workAddress: [
            { required: true, message: '请输入工作地点!' }
          ],
          requireQuantity: [
            { required: true, pattern: /^[1-9]\d*$/, message: '请输入所需人数!' }
          ],
          educationalRequirements: [
            { required: true, message: '请选择学历要求!' }
          ],
          sexRequirements: [
            { required: true, message: '请选择性别要求!' }
          ],
          professionalRequirement: [
            { required: true, message: '请选择专业要求!' }
          ],
          workExperience: [
            { required: true, message: '请选择工作经验!' }
          ],
          salarySection: [
            { required: true, message: '请选择薪资区间（元）!' }
          ],
          expectationTime: [
            { required: true, message: '请选择期待到岗时间!' }
          ]
        },
        url: {
          add: '/api/erp/hr/post/erpHrPostRequirementItem/add',
          edit: '/api/erp/hr/post/erpHrPostRequirementItem/edit',
          queryById: '/api/erp/hr/post/erpHrPostRequirementItem/queryById'
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      }
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs['form'].clearValidate();
        Object.assign(this.$data, this.$options.data())
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            if (!this.model.id) {
              this.model.id = parseInt(Math.random() * 1000000000000);
            }
            this.$emit('ok', this.model);
          }
        })
      }
    }
  }
</script>
